package com.tcoiss.webservice.controller.webapi;

import com.tcoiss.common.core.domain.R;
import com.tcoiss.common.core.web.domain.AjaxResult;
import com.tcoiss.common.log.annotation.ApiLog;
import com.tcoiss.common.component.api.model.GdAdminDivisionVo;
import com.tcoiss.common.log.annotation.Log;
import com.tcoiss.common.log.enums.BusinessType;
import com.tcoiss.webservice.domain.AddressKeyVo;
import com.tcoiss.webservice.service.IGaodeApiService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author 朱圣煌
 * 对接高德API接口
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/gaodeApi")
public class GaodeApiController {

    @Autowired
    private IGaodeApiService iGaodeApiService;

    //@ApiLog(title = "定位四级地址" ,businessType = BusinessType.EXECUTE_API)
    @GetMapping("/getDistrictsId")
    public R getDistrictsId(String location){
        Map<String, Object> distrctsMap = iGaodeApiService.getDistrictsIdByNumber(location);
        return R.ok(distrctsMap);
    }

    //@ApiLog(title = "查询地址列表" ,businessType = BusinessType.EXECUTE_API)
    @GetMapping("/queryLocations")
    public R queryLocations(AddressKeyVo vo) {
        AjaxResult result = iGaodeApiService.queryLocations(vo);
        return R.ok(result.get("data"));
    }

    /*@ApiLog(title = "查询围栏地址" , businessType = BusinessType.EXPORT)
    @GetMapping("fence/getFenceByLocation")
    public AjaxResult getFenceByLocation(AddressVo addressVo) {
        return iFencePointsService.getFenceByLocation(addressVo);
    }*/
    //@Log(title = "获取行政区划" ,businessType = BusinessType.EXECUTE_API)
    @GetMapping("/getDistrictInfo")
    public R<List<GdAdminDivisionVo>> getDistrictInfo() {
        List<GdAdminDivisionVo> result = iGaodeApiService.getDistrictInfo();
        if(result==null){
            R.fail("获取行政区划接口调用失败");
        }
        return R.ok(result);
    }




}
